package com.psdi.element;

import com.psdi.manager.ElementManager;
import com.psdi.window.GameJFrame;

import java.awt.*;

/**
 * 血条类
 * 用于显示玩家的生命值
 * 继承自ElementObject类
 */
public class Blood extends ElementObject{
    private static int height = 15;
    private static int width = GameJFrame.GAME_WIDTH;

    public Blood CreateBlood(){
        this.tag = Tag.LEVEL;
        ElementManager.getINSTANCE().addElement(this);
        return this;
    }

    @Override
    public void show(Graphics g) {
        if(!ElementManager.getINSTANCE().getGameElements().get(Tag.PLAYER).isEmpty()) {
            Player player = (Player)ElementManager.getINSTANCE().getGameElements().get(Tag.PLAYER).get(0);
            float fillRatio = player.getHp()/player.getMaxhp();

            g.setColor(Color.BLACK);
            g.drawRect(0, 20, width, height);

            g.setColor(Color.RED);
            int fillWidth = (int) (width * fillRatio);
            g.fillRect(1, 21, fillWidth, height);
        }
        else  this.setAlive(false);


    }
}
